<?php


    class Forms_EditarNodo extends Zend_Form
    {
         /*  
         * ======================================================================================
         * 
         * ALL the Zend_Forms classes performed by Jean Carlo Machado has the following scope:
         * 
         * public function init(); 
         * public function showForm($name,$destinationUrl);
         * 
         * The first one serves only to zend authenticate the fom         * 
         * The second one serves to show the form without use Zend patters
         * of forms. 
         * 
         * =======================================================================================
         * To call on the controllers or helpers scope:
         * 
         *      To show:
         *              require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                        $form = new Forms_CriarNodo();
                        $form->setAction($this->_helper->url('recivecreatenod'));
                        $form->showForm('create','/nodo/recivecreatenod');
         * 
         *      To pick back (IN THE ACTION PASSED TO SHOW FORM):
         *                  require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                            $form = new Forms_CriarNodo();

                            if($this->getRequest()->isPost())
                            {
                                $data = $this->_request->getPost();

                                print_r($data);

                                if($form->isValid($data))
                                {
                                   //DO SOMETHING
                                }
                                else
                                {
                                     $this->view->message = 'Dados Invalidos';
                                }
         * =========================================================================================
         * 
         */
        public function init()
        {
            $this->setMethod('post');
            
            
            
            $nome = $this->createElement('text','name',array('label' => 'Nome'));
            $nome->setRequired(true)
                 ->addValidator('alnum')
                 ->addValidator('stringLength',true,array(6,20));
            
            
            
            $nomeNodoPai = $this->createElement('text','nameNodoPai',array('label'=>'Nodos Pais separados por v?rgula (,)'));
            $nomeNodoPai->setRequired(false)
                        #->addValidator('alnum')
                        ->addValidator('stringLength',true,array(6,20));
            
           
            $nomeNodoFilho = $this->createElement('text','nameNodoFilho',array('label'=>'Nodos Filhos separados por v?rgula (,)'));
            $nomeNodoFilho->setRequired(false)
                        #->addValidator('alnum')
                        ->addValidator('stringLength',true,array(6,20));
            
            $aproved = new Zend_Form_Element_Select('aproved');
            $aproved->setLabel('Aprova??o')
                    ->addMultiOptions(array('yes' => 'Aprovar','no' => 'Desaprovar'));
            
            
            
            $this->addElement($nome);
            $this->addElement($nomeNodoPai);
            $this->addElement($nomeNodoFilho);
            $this->addElement($aproved);
            $this->addElement('submit','Criar',array('label'=> 'Criar Nodo'));
        }
        
        public function showForm($action,$destinationUrl,$nameNodo,$pais,$filhos)
        {
            $return = "<form name='$action' METHOD='POST' ACTION='$destinationUrl'>";
            $return.= "<input type='hidden' name='action' value='$action'>";
            $return.= " Nome:<br> <input type='text' name='name' value='$nameNodo'><br>";
            $return.= " Nodos Pais:<br> <input type='text' name='nameNodoPai' value='$pais'><br>";
            $return.= " Nodos Filhos:<br> <input type='text' name='nameNodoFilho' value='$filhos'><br>";
            $return.= " Aprovacao: <br> <select name ='aprovation'>
                                            <option value='no'>Nao
                                            <option value='yes'>Sim
                                         </select><br>";
            $return.= " <input type='submit' name='Criar' value='Confirma Edicao'></form>";
            
            echo $return;
        }
    }
?>
